﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using Ket_noi_toi_VPP_bang_mo_hinh_ba_lop.Connection;

namespace Ket_noi_toi_VPP_bang_mo_hinh_ba_lop.DAL
{
    public class KhachHang
    {
        private dbConnection Conn;

        public KhachHang()
        {
            Conn = new dbConnection();
        }

        public bool Insert(string TenKH,string DiaChi,string GioiTinh,string DienThoai,string Email)
        { 
            SqlParameter[] sqlPara=new SqlParameter[5];
            //sqlPara[0] = new SqlParameter("@MaKH",SqlDbType.NVarChar,20);
            //sqlPara[0].Value = Convert.ToString(MaKH);            
            sqlPara[0] = new SqlParameter("@TenKH",SqlDbType.NVarChar,35);                        
            sqlPara[0].Value = Convert.ToString(TenKH);
            sqlPara[1] = new SqlParameter("@DiaChi", SqlDbType.NVarChar,35);
            sqlPara[1].Value = Convert.ToString(DiaChi);           
            sqlPara[2] = new SqlParameter("@GioiTinh", SqlDbType.Char,7);
            sqlPara[2].Value = Convert.ToString(GioiTinh);           
            sqlPara[3] = new SqlParameter("@DienThoai", SqlDbType.VarChar,12);
            sqlPara[3].Value = Convert.ToString(DienThoai);            
            sqlPara[4] = new SqlParameter("@Email", SqlDbType.NVarChar,20);
            sqlPara[4].Value = Convert.ToString(Email);
            return Conn.executeInsertProcedureQuery("Insert_KH", sqlPara);
        }

        public bool Update(int MaKH,string TenKH, string DiaChi, string GioiTinh, string DienThoai, string Email)
        {
            SqlParameter[] sqlPara = new SqlParameter[6];
            sqlPara[0] = new SqlParameter("@MaKH", SqlDbType.Int);
            sqlPara[0].Value = Convert.ToString(MaKH);
            sqlPara[1] = new SqlParameter("@TenKH", SqlDbType.NVarChar, 35);
            sqlPara[1].Value = Convert.ToString(TenKH);
            sqlPara[2] = new SqlParameter("@DiaChi", SqlDbType.NVarChar, 35);
            sqlPara[2].Value = Convert.ToString(DiaChi);
            sqlPara[3] = new SqlParameter("@GioiTinh", SqlDbType.Char, 7);
            sqlPara[3].Value = Convert.ToString(GioiTinh);
            sqlPara[4] = new SqlParameter("@DienThoai", SqlDbType.VarChar, 12);
            sqlPara[4].Value = Convert.ToString(DienThoai);
            sqlPara[5] = new SqlParameter("@Email", SqlDbType.NVarChar, 20);
            sqlPara[5].Value = Convert.ToString(Email);
            return Conn.executeUpdateProcedureQuery("Update_KH",sqlPara);
        }
        
        public bool Delete(int MaKH)
        { 
            SqlParameter[] sqlPara=new SqlParameter[1];
            sqlPara[0] = new SqlParameter("@MaKH",SqlDbType.Int);
            sqlPara[0].Value = Convert.ToString(MaKH);
            return Conn.executeUpdateProcedureQuery("Delete_KH",sqlPara);
        }
        
        public DataTable SelectAll()
        {
            return Conn.excuteSelectProcedureQuery("SelectAll_KH");
        }

        public DataTable SelectID(int MaKH)
        { 
            SqlParameter[] sqlPara=new SqlParameter[1];
            sqlPara[0] = new SqlParameter("@MaKH",SqlDbType.Int);
            sqlPara[0].Value = Convert.ToString(MaKH);
            return Conn.excuteSelectProcedureQuery("SelectID_KH",sqlPara);
        }
    }
}
